package com.zs.diveinspringbootkotlin.condition

import org.springframework.context.annotation.Condition
import org.springframework.context.annotation.ConditionContext
import org.springframework.core.type.AnnotatedTypeMetadata

/**
 * 系统属性条件判断
 * @description
 * @author madison
 * @date 2021/6/3 22:28
 *
 */
class OnSystemPropertyCondition : Condition {
    override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean {
        var attributes = metadata.getAnnotationAttributes(ConditionOnSystemProperty::class.java.name)
        var propertyName: String = attributes?.get("name") as String
        var propertyValue: String = attributes?.get("value") as String
        var javaPropertyValue = System.getProperty(propertyName)
        return propertyValue == javaPropertyValue
    }
}